package com.wangyp.tower.user.controller;

import com.wangyp.tower.common.result.Result;
import com.wangyp.tower.model.user.UserInfo;
import com.wangyp.tower.user.service.UserInfoService;
import com.wangyp.tower.vo.user.LoginVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;


/**
 * @Author: Wangyp
 * @Date: 2021/4/24 8:54
 * @Description: *
 */
@Api(tags = "用户管理")
@RestController
@RequestMapping("/admin/user")
public class UserInfoApiController {

    @Autowired
    private UserInfoService userInfoService;

    @ApiOperation(value = "用户登录")
    @PostMapping("login")
    public Result login(@RequestBody UserInfo user){
        Map<String, Object>  userinfo = userInfoService.loginUser(user);
        System.out.println("user");
        System.out.println(userinfo.toString());
       return Result.ok(userinfo);
    }

    @ApiOperation(value = "用户名密码登录")
    @PutMapping("loginbyname/{name}/{password}")
    public Result loginbyname(@PathVariable String name,
                                @PathVariable Integer password){
        Map<String, Object>  userinfo = userInfoService.loginbyname(name, password);
        System.out.println(userinfo.toString());
        return Result.ok(userinfo);
    }

    @ApiOperation(value = "获取用户信息")
    @PutMapping("getUserInfo/{name}")
    public Result getUserInfo(@PathVariable String name){
        Map<String, Object> userInfo = userInfoService.getUserInfo(name);
        System.out.println(userInfo);
        return Result.ok(userInfo);
    }

    @ApiOperation(value = "获取用户数量")
    @GetMapping("getUserInfoAcount")
    public Result getUserInfoAcount() {
        int count = userInfoService.count();
        System.out.println(count);
        return Result.ok(count);
    }

}
